package com.thug.tools;

import org.springframework.aop.support.AbstractRegexpMethodPointcut;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.aop.support.RegexpMethodPointcutAdvisor;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

public class CustomRegexpMethodPointcutAdvisor extends RegexpMethodPointcutAdvisor {

	private static final long serialVersionUID = 1L;

	private String[] excludedPatterns = new String[0];

	@Override
	protected AbstractRegexpMethodPointcut createPointcut() {
		AbstractRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
		if (this.excludedPatterns != null && this.excludedPatterns.length > 0) {
			pointcut.setExcludedPatterns(this.excludedPatterns);
		}
		return pointcut;
	}

	public void setExcludedPattern(String excludedPattern) {
		setExcludedPatterns(new String[] { excludedPattern });
	}

	public void setExcludedPatterns(String[] excludedPatterns) {
		Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
		this.excludedPatterns = new String[excludedPatterns.length];
		for (int i = 0; i < excludedPatterns.length; i++) {
			this.excludedPatterns[i] = StringUtils.trimWhitespace(excludedPatterns[i]);
		}
	}

	public String[] getExcludedPatterns() {
		return this.excludedPatterns;
	}
}
